require("AWZ")
require("tsp")


app = {}
app.bid = 'com.yinxiang.kollector'
app.name = '收藏家'
t = {}
degree = 80



t['_vpn好'] = { 0x007aff, "0|0|0x007aff,-18|-8|0x007aff", degree, 333, 644, 412, 819 }




t['收藏家_欢迎'] = { 0x1cbaff, "0|0|0x1cbaff,0|-466|0xffffff,28|-507|0xffda4f,-28|-425|0xfdd84f", degree, 33, 253, 713, 932 }
    --303,657
    t['收藏家_输入前清除'] = { 0xf5f5f5, "0|0|0xf5f5f5,0|9|0xc4c4c4", degree, 647, 636, 679, 676 }
    --376,383
    
t['收藏家_创建帐户'] = { 0x000000, "0|0|0x000000,50|214|0x1cbaff,-461|214|0x1cbaff,-439|116|0x1cbaff,-545|-245|0x8c8c8c,83|-122|0xf5f5f5", degree, 26, 48, 698, 549 }
t['收藏家_创建帐户_已经发短信'] = { 0x1cbaff, "0|0|0x1cbaff,18|-1|0xffffff,-202|51|0x1cbaff,271|51|0x1cbaff,337|-372|0xf5f5f5,337|-380|0xc4c4c4", degree, 25, 54, 696, 632 }
    t['创建帐户_输入密码'] = { 0x777878, "0|0|0x777878,1|24|0x8d8d8d,-11|-31|0xf0f1f1,-2|54|0xf0f1f1", degree, 72, 384, 216, 496 }
    
t['收藏家_注册完成'] = { 0xffce00, "0|0|0xffce00,16|-7|0xffffff,14|-12|0x282829,549|-1014|0x282829", degree, 17, 137, 735, 1316 }
    --提示
t['收藏家_用户名不存在'] = { 0x00abff, "0|0|0x00abff,-18|-13|0x00abff,-106|-164|0x000000,91|-161|0x000000", degree, 156, 589, 580, 794 } 
    t['已经册-清除'] = { 0xf5f5f5, "0|0|0xf5f5f5,-255|-302|0x07ba74,-173|-591|0xf29f2a,-27|254|0x1cbaff", degree, 186, 136, 724, 1224 }
t['收藏家_用户无效'] = { 0x00abff, "0|0|0x00abff,-19|-9|0x00abff,-107|-155|0x000000,48|-157|0x2d2d2d,48|-152|0xeeefef,53|-147|0x000000", degree, 153, 584, 612, 796 }
t['收藏家_同意并继续'] = { 0x00abff, "0|0|0x00abff,-195|2|0xc8c8c8,-283|-382|0x000000,-122|-483|0x7f7f7f,11|-679|0x000000", degree, 109, 152, 607, 884 }
t['收藏家_要求不跟踪'] = { 0x007aff, "0|0|0x007aff,-80|-12|0x1183fe,153|-3|0x067dfe,25|97|0x007aff,94|40|0x79b8cd", degree, 240, 707, 513, 931 }
t['收藏家_已注册'] = { 0xffffff, "0|0|0xffffff,25|-40|0xfed94f,31|-30|0x07b973,-22|-310|0xf09716,-22|-327|0xf0930e", degree, 176, 143, 563, 583 }
t['收藏家_已注册2'] = { 0xfed94f, "0|0|0xfed94f,10|-8|0x07ba74,-243|306|0x000000,-243|287|0x000000,-211|512|0x1cbaff,298|609|0x1cbaff", degree, 55, 314, 699, 979 }    
t['收藏家_vpn_好'] = { 0x007aff, "0|0|0x007aff,-17|5|0x007aff,-77|-188|0x000000,-47|-188|0x000000,-14|-187|0x000000", degree, 132, 553, 623, 787 }

function reg()
    app.password = "AaDd112211"
    timeline = os.time()
    while ( os.time() - timeline < 120 ) do
        if active(app.bid, 5) then
            if d("收藏家_欢迎") then
                click(303,657,2)
                d("收藏家_输入前清除",true)
                app.phone = m.getPhone()
                if app.phone then
                    input(app.phone)
                    delay(1)
                    click(376,383,2)
                    d("收藏家_欢迎",true)
                else
                    click(376,383)
                end
            elseif d("收藏家_创建帐户", true)then
            elseif d("收藏家_创建帐户_已经发短信")then
                if d("创建帐户_输入密码",true)then
                    input(app.password)
                    delay(2)
                end
                click(228,324)
                yzm = m.getMessage()
                if yzm ~= nil or yzm ~= '' then
					click(228,324)
					delay(2)
					input(yzm)
				else
				    return
                end
                local i = 0
                while i < 10  and d("收藏家_创建帐户_已经发短信", true) do
			        delay(1)
			        i=i+1
			        if i > 6 then vpnx() end
                end
            elseif d("收藏家_注册完成") then
                app.other = '注册成功'
                up()
                return true
            elseif d("收藏家_用户无效",true)then
                app.other = '用户无效'
                up()
                return true
            elseif d("收藏家_vpn_好",true)then
            else
                if d("收藏家_同意并继续", true) then
                    d("收藏家_欢迎",true)
                end
                d("收藏家_要求不跟踪", true)
                if d("收藏家_用户名不存在", true) then
                    app.other = '用户名不存在'
                    up()
                    return true
                end
                if d("收藏家_已注册") or d("收藏家_已注册2")then
                    d("已经册-清除", true)
                    app.other = '注册过拉黑'
                    up()
                    return true
                end
                click(376,383)
            end
        end
        delay(1)
    end
end


function awz_()
	local logTxt = '/var/mobile/iggresult.txt'
	out_time = os.time()
	while os.time()-out_time <= 10 do
		if fileExists(logTxt)then
			local new = readFile(logTxt)[1]
			log(new)
			if new == "1" then
				return true
			elseif new == "3" then
				toast('IP-->重复请注意',1)
				return true
			elseif new == '2' then
				toast('一键新机中',2)
			end
			mSleep(1000)
		end
		mSleep(1000* 1)
	end
end


t['awz_一键新机'] = { 0x6f7179, "0|0|0x6f7179,105|-88|0x34c759,534|-93|0x34c759,361|-6|0x6f7179", 90, 21, 488, 740, 865 }
t['awz_返回'] = { 0x007aff, "0|0|0x007aff,70|-4|0x007aff,73|-5|0xf9f9f9,77|0|0x007aff", 90, 5, 44, 732, 114 }
t['awz_正在新机'] = { 0x34c759, "0|0|0x34c759,431|-3|0x34c759,-55|38|0xd2d3d5,369|40|0xd4d5d7,367|221|0xd4d4d6,-56|224|0xd1d1d4", degree, 32, 496, 736, 780 }

function awzNew_()
    timeLine = os.time()
	outTime = 60 * 0.5
	while (os.time()-timeLine < outTime) do
		if active("AWZ",3)then
            if d("awz_一键新机", true ) then
                local check = 0
                local todo = false
                while (check < 30 and d("awz_正在新机") ) do
                    delay(1)
                    check = check + 1
                    log("awz_正在新机")
                end
                return true
            elseif d("awz_返回", true) then
            end
		end
		d("_vpn好", true)
		mSleep(1000)
	end
	nLog('新机超时')
end

function up()
    uphb()
	local url = 'http://wenfree.cn/api/Public/idfa/?service=idfa.idfa'
	local idfalist ={}
	idfalist.name = app.name
	idfalist.idfa = app.phone
	idfalist.account = app.phone
	idfalist.account = app.password
	idfalist.other = app.other
	return post(url,idfalist)
end

function uphb()
	local url = 'http://hb.wenfree.cn/api/Public/idfa/?service=idfa.idfa'
	local idfalist ={}
	idfalist.name = app.name
	idfalist.idfa = app.phone
	idfalist.account = app.phone
	idfalist.account = app.password
	idfalist.other = app.other
	return post(url,idfalist)
end

function _Server_getnew()
	phone_name = getDeviceName()
	phone_imei = getDeviceName()
	log(phone_name)
	log(phone_imei)
	return {
		login=(function()
			return	
		end),
		addBlack=(function()
			return	
		end),
		getPhone = (function()
				RetStr = get('http://sms.wenfree.cn/public/?s=App.SmsNew.GetPhone'.."&imei="..phone_imei.."&phonename="..phone_name)
				if RetStr then
				-- 	RetStr = json.decode(RetStr)
					log(RetStr)
					if RetStr.data.meg == success or RetStr.data.meg == 'success' then
						phone = RetStr.data.phone
						log(phone)
					end
				else
					log(RetStr)
				end
				delay(3)
				return phone
		end),
		getMessage=(function()
			local Msg
			local total = 15
            for i=1,total,1 do
				delay(3)
				RetStr = get("http://sms.wenfree.cn/public/?s=App.SmsNew.getMessage".."&imei="..phone_imei.."&phonename="..phone_name)
				if RetStr then
				-- 	RetStr = json.decode(RetStr)
					log(RetStr)
					if RetStr.data.meg == success or RetStr.data.meg == 'success' then
						Msg = RetStr.data.sms
						if type(tonumber(Msg))== "number" then log(Msg); return Msg 
						else
							log(Msg)
							local i,j = string.find(Msg,"%d+")
							Msg = string.sub(Msg,i,j)
							if type(tonumber(Msg))== "number" then log(Msg); return Msg end
						end
					end
				end
				toast(tostring(RetStr).."\n"..i.."次共".. total .."次")
				delay(3)
            end
            return false
        end),
	}
end

function main()
    while ( true ) do
        log('准备一键新机')
        d("_vpn好", true)
        if awzNew_() then
            if vpn() then
                reg()
            end
        end
        vpnx()
    end
end


m = _Server_getnew()
main()














































